package com.hc.common.bean;

import com.hc.common.enums.ResultEnum;

import java.util.Date;

/**
 * 结果工具类
 *
 * @author hecai
 */
public class ResultUtil {

    /**
     * 操作成功，返回具体的数据、结果码和提示信息
     *
     * @return 结果
     */
    public static Result success() {
        final Result result = new Result(ResultEnum.OK.getCode(), ResultEnum.OK.getMsg(), null);
        return result;
    }

    public static Result success(String msg) {
        final Result result = new Result(ResultEnum.OK.getCode(), msg, null);
        return result;
    }

    /**
     * 操作失败，返回具体的数据、结果码和提示信息
     *
     * @return 结果
     */
    public static Result fail() {
        final Result result = new Result(ResultEnum.ERROR.getCode(), ResultEnum.ERROR.getMsg(), null);
        return result;
    }

    public static Result fail(String msg) {
        final Result result = new Result(ResultEnum.ERROR.getCode(), msg, null);
        return result;
    }

    /**
     * 操作成功，返回具体的数据、结果码和提示信息
     *
     * @param resultEnum 枚举
     * @return 结果
     */
    public static Result success(ResultEnum resultEnum) {
        final Result result = new Result(resultEnum.getCode(), resultEnum.getMsg(), null);
        return result;
    }

    /**
     * 操作失败，返回具体的数据、结果码和提示信息
     *
     * @param resultEnum 枚举
     * @return 结果
     */
    public static Result fail(ResultEnum resultEnum) {
        final Result result = new Result(resultEnum.getCode(), resultEnum.getMsg(), null);
        return result;
    }

    public static void main(String[] args) {
        Result r1 = ResultUtil.success().setMsg("haha");
        System.out.println(r1);
        System.out.println(r1.getMsg() == null);
        System.out.println(r1.getMsg() instanceof String);

        final Result r2 = ResultUtil.success(ResultEnum.OK);
        System.out.println(r2);
        final Result r3 = ResultUtil.success().setData(new Date());
        final Result r4 = ResultUtil.success(ResultEnum.OK);
    }
}
